package com.tran.app.dao

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.tran.app.data.Course
import com.tran.app.data.CourseSelection
import com.tran.app.data.CourseSelectionCancellation
import com.tran.app.data.PlainData
import com.tran.app.data.Teacher
import com.tran.app.data.UserInfo
import com.tran.app.data.UserPlane

@Database(entities = [UserInfo::class,UserPlane::class,PlainData::class,Teacher::class,Course::class,
                     CourseSelection::class,CourseSelectionCancellation::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
    abstract fun userInfoDao(): UserInfoDao
    abstract fun userPlaneDao(): UserPlaneDao
    abstract fun plainDataDao(): PlainDataDao
    abstract fun teacherDao(): TeacherDao
    abstract fun courseDao(): CourseDao
    abstract fun CourseSelectionDao(): CourseSelectionDao
    abstract fun courseSelectionCancellationDao(): CourseSelectionCancellationDao
    companion object {
        @Volatile
        private var INSTANCE: AppDatabase? = null

        fun getInstance(context: Context): AppDatabase {
            val tempInstance = INSTANCE
            if (tempInstance != null) {
                return tempInstance
            }
            synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    AppDatabase::class.java,
                    "app_database"
                ).build()
                INSTANCE = instance
                return instance
            }
        }
    }
}